<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<html>
<head>
    <title>高血脂随访</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/lib/dataTables.bootstrap.css" type="text/css">
    <link rel="stylesheet" href="../assets/css/views/modules/_common.scss">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <link rel="stylesheet" href="${assets}/css/views/department/departmentMgr.css">
    <script src="${newframe}/js/compatible.js"></script>
    <script src="${js}/jquery-1.9.1.min.js"></script>
    <script src="../assets/js/views/vue.min.js"></script>
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <style>
        #news,
        #card{
            width: 80px;
            height: 17px;
            font-size: 16px;
            font-weight: normal;
            font-stretch: normal;
            color: #666666;
        }
        #example_paginate{
            margin-top:15px;
            width:100%;
            text-align: center;
        }
        .form{
            margin-bottom:0px !important;
        }
        .content{
            height:auto !important;
        }
        #example_paginate{
            padding-bottom:30px;
        }
        .dataTables_empty{
            line-height:30px;
        }
        .typePerson{
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            overflow: hidden;
            width:85%;
            margin:0 auto;
        }
    </style>
</head>
<body>
<div class="wrap">
    <%@ include file="../../breadline.jsp" %>
    <div class="content">
        <h1>高血脂随访</h1>
        <div class="form">
            <label id="news" for="infoSearch">信息搜索:</label>
            <input id="infoSearch" type="text" class="SN" placeholder="病人姓名">
            <input id="searchDoctor" type="text" placeholder="建档医生" class="SN">
            <label id="card" for="IDNumber" >身份证:</label>
            <input type="text" id="IDNumber" class="SN" placeholder="输入身份证号">
            <button class="search" id="query" onclick="refreshTable();">搜索</button>
        </div>
        <div id="tablepart" style="margin-left:19px;">
            <table id="example" class="display" cellspacing="10" width="100%">
                <thead>
                <tr style="background:#e6e6e6;">
                    <th>姓名</th>
                    <th>性别</th>
                    <th>id</th>
                    <th>出生日期</th>
                    <th>身份证</th>
                    <th>人群</th>
                    <th>建档医生</th>
                    <th>建档机构</th>
                    <th>建档时间</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
    <div class="loading" style="display: none;">
        <img src="${newframe }/images/slidebar/loading.gif" class="loadingImg">
    </div>
</div>
<script>
    var url = '${URL_PPPATIENTBASE_LIST_BY_SEARCH}';
    var diseasesType = 3;
    var href = window.location.search;
    var isStorage = false;
    // 判断当前页面是否从面包线跳转过来
    if(  href.indexOf("isStorage") != -1){
        isStorage = true
    }
    var number = 0;
    function initTable() {
        table = $('#example').DataTable({
            "dom": "<'row'<'col-xs-2'l><'#mytool.col-xs-10'><'col-xs-6'f>r>" +
            "t" +
            "<'row'<''i><''p>>",
            "bFilter": false,//去掉搜索框
            "bAutoWidth": true, //自适应宽度
            "info": false,
            "bSort": false,
            "sPaginationType" : "full_numbers",
            "ordering": false,//是否允许Datatables开启排序
            "bProcessing" : true,
            "bServerSide" : true,
            "searching" : false, //去掉搜索框方法一
            'lengthChange' : false,
            "oPaginate":false,
            "sAjaxSource":url,
            "iDisplayStart" :number,
            "sAjaxDataProp": "dataList",//查询后，返回的集合
            "fnServerData": function ( sSource, aoData, fnCallback ) {  //查询条件
                aoData.push(
                    {
                        "name": "realname",
                        "value": $("#infoSearch").val()
                    },
                    {
                        "name": "doctor",
                        "value": $("#searchDoctor").val()
                    },
                    {
                        "name": "idcard",
                        "value": $("#IDNumber").val()
                    },
                    {
                        "name": "diseasesType",
                        "value": diseasesType
                    }
                ),
                    $.ajax( {
                        "dataType": 'json',
                        "url": sSource,
                        "type":'post',
                        "data": aoData,
                        "success": function(resp){
                            console.log(resp)
                            fnCallback(resp)
                        }
                    } );
            },
            "aoColumns" : [{
                "targets": 0,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    $(nTd).html('' +
                        '&nbsp;&nbsp;<a href="#" onClick="Then(this)" style="color:black;border-bottom:#35acfd dashed 1px">'+oData.realname+'</a>' +
                        '');
                }
            }, {
                "targets": 1,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    if( oData.gender === 1 ){
                        $(nTd).text("男")
                    }else if( oData.gender === 2 ){
                        $(nTd).text("女")
                    }else{
                        $(nTd).text("")
                    }
                }
            }, {
                "mDataProp" : "id","visible":false
            }, {
                "targets": 3,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    if( oData.idcard.length === 18 ){
                        oData.birthday = oData.idcard.slice(6,14).slice(0,4) + '-' + oData.idcard.slice(6,14).slice(4,6) + '-' + oData.idcard.slice(6,14).slice(6,8)
                    }else{
                        oData.birthday = ""
                    }
                    $(nTd).text(oData.birthday)
                }
            },{
                "targets": 4,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    $(nTd).html("<a href='javascript:void(0)' data-id=" + oData.idcard + " onclick='Go(this)' class='searchBtn'>" + oData.idcard.slice(0,6) + '********' + oData.idcard.slice(14,18) + "</a>");
                }
            },{
                "targets": 5,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    $(nTd).html('<p class="typePerson"'+ 'title=' + Type(oData.diseasesType) + '>'+Type(oData.diseasesType)+'</p>')
                }
            },{
                "targets": 6,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    $(nTd).html('<p class="typePerson"'+ 'title=' + isNull(oData.doctor) + '>'+isNull(oData.doctor)+'</p>')
                }
            },{
                "targets": 7,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    $(nTd).html('<p class="typePerson"'+ 'title=' + isNull(oData.hospName) + '>'+isNull(oData.hospName)+'</p>')
                }
            },{
                "targets": 8,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    $(nTd).text(oData.createdtime.slice(0,10))
                }
            }],
            "createdRow": function ( row, data, index ) {

            },
            "oLanguage": {//插件的汉化
                "sLengthMenu": "32",
                "sInfoEmpty" : "没有数据",
                "sInfoFiltered" : "(从 _MAX_ 条数据中检索)",
                "oPaginate" : {
                    "sFirst" : "",
                    "sPrevious" : "<b>上一页<b>",
                    "sLast" : "",
                    "sNext" : "<i>下一页</i>"

                },
                "sZeroRecords" : "没有检索到数据",
                "sProcessing" : "<img src='' />",
                "sSearch" : "搜索"
            }

        });
    }
    $(document).ready(function() {
        if( isStorage ){
            number = (Number(sessionStorage.getItem('pageNumber'))-1)*10;
        }
        initTable();
    })
    function isNull(data){
        var str = '';
        if( data != null ){
            str = data
        }
        return str
    }
    function Go(obj){
        var rowIndex = $(obj).parents("tr").index();
        var id = $('#example').DataTable().row(rowIndex).data().id;//此处拿到隐藏列的id
        var name = $(obj).attr('data-id');
        // 判断
        var Type = obj.parentNode.parentNode.children[4].children[0].innerText;
        // var name = obj.innerText;

        // 判断
        // var Type = obj.parentNode.parentNode.children[4].innerText
        var ids = typePerson(Type);
        console.log(ids)
        console.log(ids)
        $.ajax({
            url:"${URL_SCREENING_GETBREADLINE}",
            dataType:'json',
            type:'post',
            success:function(data){
                breadLine = JSON.parse(data.data)
                var url = '${URL_ACCOMPANY_BFACCOMPANYS}?idcard=' + name + '&id=' + id +'&diseasesType='+diseasesType+'&type='+ids
                breadLine.push({
                    name:'随访信息',
                    href:url
                })
                $.ajax({
                    url:'${URL_SCREENING_SAVEBREADLINE}',
                    data:{
                        breadLine:JSON.stringify(breadLine)
                    },
                    dataType:'json',
                    type:'post',
                    success:function(data){
                        parent.showSrc('${URL_ACCOMPANY_BFACCOMPANYS}?idcard=' + name + '&id=' + id +'&diseasesType='+diseasesType+'&type='+ids)
                    }
                })
            }
        })
    }
    function Then(obj){
        var idDom = obj.parentNode.parentNode.children[3].children[0];
        var idcard = $(idDom).attr('data-id');
        var rowIndex = $(obj).parents("tr").index();
        var id = $('#example').DataTable().row(rowIndex).data().id;//此处拿到隐藏列的id
        // var Type = obj.parentNode.parentNode.children[4].innerText
        var ids = typePerson(Type);
        console.log(ids)
        $.ajax({
            url:"${URL_SCREENING_GETBREADLINE}",
            dataType:'json',
            type:'post',
            success:function(data){
                breadLine = JSON.parse(data.data)
                var url = '${URL_ACCOMPANY_BFACCOMPANYS}?idcard=' + idcard + '&id=' + id +'&diseasesType='+diseasesType+'&type='+ids
                breadLine.push({
                    name:'随访信息',
                    href:url
                })
                $.ajax({
                    url:'${URL_SCREENING_SAVEBREADLINE}',
                    data:{
                        breadLine:JSON.stringify(breadLine)
                    },
                    dataType:'json',
                    type:'post',
                    success:function(data){
                        parent.showSrc('${URL_ACCOMPANY_BFACCOMPANYS}?idcard=' + idcard + '&id=' + id +'&diseasesType='+diseasesType+'&type='+ids)
                    }
                })
            }
        })
    }
    function getValue(){
        var oTable = $('#example').dataTable();
        var oSettings = oTable.fnSettings();
        // 获取页码值
        return oSettings._iDisplayStart;
    }
    window.onbeforeunload=function(e){
        var e = window.event||e;
        var pageNumber = getValue()
        // 获取当前页码
        if( pageNumber == 0 ){
            pageNumber = 1;
        }else{
            pageNumber = pageNumber/10 + 1;
        }
        console.log(pageNumber)
        // 保存在本地
        sessionStorage.setItem('pageNumber',pageNumber);
    }
</script>
</body>
</html>
